import { createStore, Store, useStore as baseUseStore } from 'vuex'
import { InjectionKey } from 'vue'
import user from './modules/user'
export interface State {
  // 根据实际情况里面定义自己需要的类型
  collapsed: boolean;
  user?: any
}

// 定义 injection key
export const key: InjectionKey<Store<State>> = Symbol('gp')
export default createStore<State>({
  state: {
    collapsed: false
  },
  getters: {
    token: state => state.user.token,
    isLogin: state => state.user.isLogin
  },
  mutations: {
    changeCollapsed (state: State) {
      state.collapsed = !state.collapsed
      localStorage.setItem('collapsed', state.collapsed.toString())
    }
  },
  actions: {
  },
  modules: {
    user
  }
})
// 定义自己的 `useStore` 组合式函数
export function useStore () {
  return baseUseStore(key)
}
